<?php
$pd=false;
$arry = include ("./arry.php");
if($_GET!=null){
    $id=$_GET['id'];
    $name = $arry[$id]['name'];
    $neirong=$arry[$id]['neirong'];
}
if($_POST!=null){
    if($_POST['xname']!=null){
        $xname=$_POST['xname'];
        $arry[$id]['name']=$xname;
        $pd=true;
    }
    if($_POST['xneirong']!=null){
        $xneirong=$_POST['xneirong'];
        $arry[$id]['neirong']=$xneirong;
        $pd=true;
    }
    $str=var_export($arry,TRUE);
    $nr=<<<nr
<?php
return {$str} ?>
nr;
    file_put_contents('./arry.php', $nr);
}
?>
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Document</title>
    <link rel="stylesheet" href="./template/css/bootstrap.css">
    <link rel="stylesheet" href="./template/css/bootstrap-theme.css">
    <link rel="stylesheet" href="./template/css/buttons.css">
    <link rel="stylesheet" href="./template/css/main.css">
</head>
<body>
<nav class="navbar navbar-default navbar-fixed-top">
    <div class="container">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle collapsed" data-toggle ="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="">我的留言板</a>
        </div>
        <div id="navbar" class="navbar-collapse collapse">
            <ul class="nav navbar-nav">
                <li role="presentation">
                    <a href="">
                        留言数量
                            <span class="badge">
                                <?php
                                echo count($arry);
                                ?>
                            </span>
                    </a>
                </li>
            </ul>
        </div>
    </div>
</nav>

<br/>
<br/>
<br/>
<div class="container theme-showcase" role="main">
    <div class="row">
        <?php
            if($pd==true) {
                ?>
                <div class="alert alert-success" role="alert">
                    <h4>修改完成！</h4>
                    <a href="index.php" class="alert-link">点击返回</a>
                </div>
                <?php
            }
        if($pd==false) {
            ?>
            <form class="form-inline" method="post" action="">
                <div class="col-sm-12">
                    <div class="form-group">
                        <label for="exampleInputName2">昵称：</label>
                        <input type="text" class="form-control" id="exampleInputName2" value="<?php
                        echo $name;
                        ?>" name="xname">
                    </div>
                    <input type="submit"
                           class="button button-glow button-rounded button-action button-primary button-small"
                           value="修改">
                </div>
                <div class="col-sm-12">
                <textarea class="form-control message" rows="5" name="xneirong" ><?php
                echo $neirong;
                ?></textarea>
                </div>
            </form>
            <?php
        };
        ?>
    </div>
</div>
<script src="./template/js/jquery-1.11.3.js"></script>
<script src="./template/js/bootstrap.js"></script>
<script src="./template/js/main.js"></script>
</body>
</html>